Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] 배포 API 붙이기 #160

Merged
merged 13 commits into from
Nov 29, 2024
Merged

[FEATURE] 배포 API 붙이기 #160

merged 13 commits into from
Nov 29, 2024

Conversation

eonseok-jeon
Copy link
Member

@eonseok-jeon eonseok-jeon commented Nov 29, 2024

✅ PR Point

  • 배포 api 붙이기 완료
  • presigned url api 붙이기 완료

presigned url 보내는 로직

map을 이용해서 코드량을 줄일 수 있었으나 가독성이 많이 떨어져서 그냥 펼쳐뒀습니다

채택하지 않았던 '줄인 코드' 보기
import { useMutation } from 'react-query';
import { sendData, sendDataConfirm, sendPresignedURL } from './api';

interface UseMutateSendDataProps {
  headerImageFile: File;
  coreValueImageFiles: File[];
  memberImageFiles: File[];
  recruitHeaderImageFile: File;
}

const useMutateSendData = ({
  headerImageFile,
  coreValueImageFiles,
  memberImageFiles,
  recruitHeaderImageFile,
}: UseMutateSendDataProps) => {
  const { mutate: sendMutate, isLoading: sendIsLoading } = useMutation({
    mutationFn: (data) => sendData(data),
    onSuccess: async (res: any) => {
      const {
        generation,
        coreValues,
        headerImage: headerImageURL,
        members,
        recruitHeaderImage: recruitHeaderImageURL,
      } = res.data;

      try {
        const imageUploadTasks = [
          { url: headerImageURL, file: headerImageFile },
          ...coreValues.map((value, index) => ({
            url: value.image,
            file: coreValueImageFiles[index],
          })),
          ...members.map((member, index) => ({
            url: member.profileImage,
            file: memberImageFiles[index],
          })),
          { url: recruitHeaderImageURL, file: recruitHeaderImageFile },
        ];

        await Promise.all(
          imageUploadTasks.map(({ url, file }) =>
            sendPresignedURL(url, file).catch((error) => {
              console.error(`Failed to upload ${file.name}:`, error);
              throw error;
            }),
          ),
        );

        const finalResponse = await sendDataConfirm({ generation });
        return finalResponse;
      } catch (error) {
        console.error('Error during file upload or confirmation:', error);
        throw error;
      }
    },
  });

  return { sendMutate, sendIsLoading };
};

export default useMutateSendData;

type error

openAPI 쓰는 과정에서 타입 에러가 많이 나네요ㅜ
죄송합니다,,, 일단 any를 많이 넣어뒀는데, 배포 후 다시 수정해야 할 거 같아요

테스트

현재 개발 서버가 닫힌 관계로 api 요청 정상적으로 되는지 테스트는 못했어요
이후 서버 복구되면 테스트 해야할 거 같습니다!

하드코딩

주용이 부분은 API request data가 아직 하드 코딩 되어있어요
추후에 수정 필요합니다!

스크린샷 2024-11-29 오전 11 25 50

@eonseok-jeon eonseok-jeon self-assigned this Nov 29, 2024
@eonseok-jeon eonseok-jeon linked an issue Nov 29, 2024 that may be closed by this pull request
Copy link

height bot commented Nov 29, 2024

Link Height tasks by mentioning a task ID in the pull request title or commit messages, or description and comments with the keyword link (e.g. "Link T-123").

💡Tip: You can also use "Close T-X" to automatically close a task when the pull request is merged.

Copy link

cloudflare-workers-and-pages bot commented Nov 29, 2024

Deploying sopt-admin with  Cloudflare Pages  Cloudflare Pages

Latest commit: 888d380
Status: ✅  Deploy successful!
Preview URL: https://f81f472f.sopt-admin.pages.dev
Branch Preview URL: https://bug-org-openapi-spec-type.sopt-admin.pages.dev

View logs

Copy link
Member

@lydiacho lydiacho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

완전 고생 많우셨습니다!!! 추후 점진적으로 코드 개선해보아요 🚀🚀🚀🚀🚀🚀

@eonseok-jeon eonseok-jeon merged commit 1a14aec into dev Nov 29, 2024
2 checks passed
@eonseok-jeon eonseok-jeon deleted the feature-org-api branch December 3, 2024 00:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] 배포 API 붙이기
2 participants